package bid.yanhj.common.core;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import bid.yanhj.common.service.FormatService;
import bid.yanhj.common.util.LocalMap;
import bid.yanhj.common.util.RequestUtil;

/**
 * controller拦截器.
 * 
 * @author yanhaijiang
 *
 */
public class Interceptor implements HandlerInterceptor {

	/**
	 * log.
	 */
	private static final Logger LOG = LoggerFactory.getLogger(Interceptor.class);

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		FormatService.init(request.getRequestURI());
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
        LOG.info(FormatService.accFormat(RequestUtil.getRequestParams(request)));
        LocalMap.destroy();
	}

}